home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSHJ2 / DSHY.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  4.4 KB  |  192 lines

  1. #include    "dshy.h"
  2. #include    "comp.h"
  3.  
  4. extern    unsigned char    *Xdict_srch();
  5.  
  6. char    RULE_LD, SAV_RULE, DICT_LD;
  7. struct    {                /* Henry Nguyen 6/15/88        */
  8.     char    hyin;            /* # of char before hyphen    */
  9.     char    hyut;            /* # of char after  hyphen    */
  10. }    HY;            /* To avoid conflict with cp struct    */
  11.  
  12. /********************************************************/
  13. /*    ENTRY POINT FOR ATARI AUTOMATIC HYPHENATION     */
  14. /********************************************************/
  15. /*
  16.     ON EXIT:
  17.  
  18.     hyph_index =  Number of hyphenation points found
  19.  
  20.     HY_TYPE = 1, EM or EN dash found
  21.     HY_TYPE = 2, hard hyphen found
  22.     HY_TYPE = 3, (EM or EN) AND hard hyphen found
  23.     HY_TYPE = 4, DH found
  24.     HY_TYPE = 0, none of above found (logic hyphenation)
  25. */    
  26. hypchk(sp,ep)
  27. unsigned char *sp, *ep;
  28. {
  29.     unsigned int  *ofsptr, chrcnt, nohcnt;
  30.     unsigned char nohyph, c, ct, *wrkptr, wrd_lngth;
  31.  
  32.     HY.hyin = cp.nbefhyp;        /* # of char before hyphen    */
  33.     HY.hyut = cp.nafthyp;        /* # of char after  hyphen    */
  34.     wrkptr = bgnptr = sp;
  35.     endptr = ep;
  36.     wrkend = wrdbuf;
  37.     ofsptr = hyofs;
  38.     dashct = HY_TYPE = DHfnd = MNdash = 0;
  39.     hypcnt = ct = nohyph = cmd_lngth = 0;
  40.     nohcnt = hyph_index = chrcnt = 0;
  41.     while (wrkptr < endptr && dashct < 65) {
  42.       c = *wrkptr++;
  43.       if (tagc(c)) {            /* to be redone...    */
  44.         chrcnt += 2; ++wrkptr; continue;
  45.       }
  46.       else if (c == DH || c == '-' || c == MDASH || c == NDASH) {
  47.         cmd_lngth = 0; MNdash = 1; ++nohyph;         
  48.         if (c == DH) {
  49.           if (hypcnt) {
  50.             for (ct = 0;ct < hypcnt;++ct) {
  51.           if (!(hyphens[ct] & 0x80)) hyphens[ct] = 255;
  52.         }
  53.           }
  54.           hyphens[hypcnt++] = ((nohcnt - 1) | 0x80);
  55.           *ofsptr = (chrcnt + 1);
  56.           DHfnd = 1; HY_TYPE = 4;
  57.         }
  58.         else if (!DHfnd) {
  59.         if (c == '-') HY_TYPE |= 2;
  60.         else          HY_TYPE |= 1;
  61.         hyphens[hypcnt++] = (nohcnt - 1);
  62.         *ofsptr = (chrcnt + 1);
  63.         }
  64.         else continue;
  65.         ++hyph_index; ++chrcnt;
  66.       }
  67.       else {
  68.         if (halpha(c)) {
  69.         ++alphact;
  70.         if (c < 0x80) c |= ' ';
  71.         }
  72.         else {
  73.         if (!alphact) c = 0;
  74.         else ++nohyph;
  75.         }
  76.         *wrkend++ = c; *wrkend = 0;
  77.         if (MNdash) {
  78.         *ofsptr++ = (chrcnt - cmd_lngth);
  79.         ++chrcnt;
  80.         MNdash = 0;
  81.         }
  82.         else *ofsptr++ = chrcnt++;
  83.         ++nohcnt; ++dashct;
  84.       }
  85.     }
  86.     if (nohyph) {
  87.       while (!(halpha(*(wrkend - 1)))) {
  88.         --wrkend; --nohyph;
  89.       }
  90.     }
  91.     wrd_lngth = (wrkend - wrdbuf);
  92.     --wrkend;
  93.     if (wrd_lngth >= (HY.hyut + HY.hyin)) {
  94.       if (!nohyph) {
  95.         if (DICT_LD && (xptr = Xdict_srch(wrdbuf))) {
  96.           for (c = ct = 0;*xptr;++xptr,++c) {
  97.             if (*xptr == '-') {
  98.           hyphens[ct++] = --c; ++hyph_index;
  99.             }    
  100.           }
  101.         }
  102.         else {
  103.           if (RULE_LD) rule_hyph(wrdbuf,wrkend);
  104.         }
  105.       }
  106.     }
  107.     if (hyph_index) set_ptrs(wrd_lngth,nohyph);
  108. }
  109.  
  110. set_ptrs(wrd_lngth,nohyph)
  111. unsigned char wrd_lngth, nohyph;
  112. {
  113.     unsigned char ct, **WRK_HYPH_PTR;
  114.     unsigned int  cnt, *ofsptr, *tmptr;
  115.  
  116.     WRK_HYPH_PTR = hyptr;
  117.     ofsptr = hyofs;
  118.     ct = 0;
  119.     cnt = hyph_index;
  120.     if (!nohyph) {
  121.       if (wrd_lngth < HY.hyut) {
  122.         wrd_lngth = HY.hyut;
  123.         HY.hyin = 0;
  124.       }
  125.       else wrd_lngth -= HY.hyut;
  126.     }
  127.     while (cnt) {
  128.       if (hyphens[ct] == 0xff) {
  129.         --cnt; --hyph_index; ++ct;
  130.         continue;
  131.       }
  132.       hyphens[ct] &= 0x7f;            /* strip upper bit */
  133.       if (!HY_TYPE) {
  134.         if ((hyphens[ct]+1) < HY.hyin ||
  135.           (hyphens[ct]+1) > wrd_lngth) {
  136.           --hyph_index; ++ct; --cnt; continue;
  137.         }
  138.       }
  139.       tmptr = hyofs;
  140.       tmptr += hyphens[ct]+1;
  141.       *WRK_HYPH_PTR++ = (bgnptr + *tmptr);
  142.       ++ofsptr; --cnt; ++ct;
  143.     } 
  144. }
  145.  
  146. /*
  147.     Exception Dictionary loading routine
  148. */
  149. ldict(file_ID)
  150. unsigned int file_ID;
  151. {
  152.     if (read(file_ID,X_BUF,XDSIZ) < 0)
  153.          DICT_LD = 0;
  154.     else DICT_LD = 1;
  155.     close(file_ID); return(DICT_LD);
  156. }
  157.  
  158. unsigned char *Xdict_srch(s)
  159. char *s;
  160. {
  161.     unsigned char *xwrdptr, *jmp_ptr, *srch, *trgt;
  162.     unsigned int *xofsptr;
  163.  
  164.     xofsptr = &X_BUF[4];
  165.     xofsptr += ((*s & 0x1f) - 1);
  166.     if (*xofsptr) xwrdptr = (X_BUF + *xofsptr);
  167.     else return(NULP);
  168.     while (*xwrdptr == *s) {
  169.       jmp_ptr = (xwrdptr - 1);
  170.       for (srch = s,trgt = xwrdptr;*srch;++srch,++trgt) {
  171.         if (*trgt == '-') --srch;
  172.         else if (*srch != *trgt) break;
  173.       }
  174.       if (!(*srch)) break;
  175.       if (*trgt > *srch) return(NULP);
  176.       xwrdptr += (*jmp_ptr + 2);
  177.     }
  178.     if (*xwrdptr == *s && !(*trgt)) return(xwrdptr);
  179.     else return(NULP);
  180. }
  181.  
  182. /*
  183.     Function to initialize hyphenation parameters
  184. */
  185. inithyph()
  186. {
  187.     int    i;
  188.     for (i = 0;i < 65;++i)
  189.         hyptr[i] = NULP;
  190.     RULE_LD = SAV_RULE = DICT_LD = 0;
  191. }
  192.